/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sunspotworld.demo;

import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;

import java.text.DateFormat;
import java.util.Date;
/**
 *
 * @author thang
 * write sensor data in text file
 * overwrite file: raw_sensor_data.txt
 */



public class RawDB {

    DateFormat fmt = DateFormat.getDateTimeInstance();
    PrintWriter outputStream = null;

    public RawDB(){

    }

    public void openFile(){
        try{
            outputStream = new PrintWriter(new FileOutputStream("../../../temp/raw_sensor_data.txt", true));
        }
        catch(FileNotFoundException e){
            System.out.println("Error opening the file ~/study/project1/temp/raw_sensor_data.txt");
            System.exit(0);
        }
    }

    public void addData(long time, int light, int temperature, double accelX, double accelY, double accelZ, int tiltX, int tiltY, int tiltZ){
        openFile();
        outputStream.print(fmt.format(new Date(time)) + ";");
        outputStream.print("Light;" + light + ";");
        outputStream.print("Temperature;" + temperature + ";");
        outputStream.print("AccelerometerX;" + accelX + ";");
        outputStream.print("AccelerometerY;" + accelY + ";");
        outputStream.print("AccelerometerZ;" + accelZ + ";");
        outputStream.print("TiltX;" + tiltX + ";");
        outputStream.print("TiltY;" + tiltY + ";");
        outputStream.print("TiltZ;" + tiltZ + "\n");
        outputStream.close();
    }
}
